﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XF.Common;
using XF.Meeting.Entity.CommonEntity;
using XF.Meeting.Entity.DTO;
using XF.Meeting.Entity.Query;
using XF.Meeting.Entity.View;
using XF.Meeting.IDal;
using XF.Sugar.IService;
using XF.Meeting.Entity.dbEntity;
using System.Data;
using XF.Common.WeChat;
using System.Threading;
using EWS;

namespace XF.Meeting.Service
{
    public class ConferenceRoomService : BaseService, IConferenceRoomService
    {
        private IMeetingDal dal = null;
        private ISettingDal setdal = null;
        private IUpLoadDal upLoadDal = null;
        private IUserDAL userdal = null;
        private IExchangeToDbDal exchangeToDbDal = null;
        ISettingSystemService setting = new SettingService("", "");
        private readonly int PassCode = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PassCode"]);
        //单人每天预约次数
        private readonly int FrequencyLimit = Convert.ToInt32(UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["FrequencyLimit"])));
        //会议纪要没有上传的小时数限制
        private readonly int MinutesHours = Convert.ToInt32(UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MinutesHours"])));
        //提前分钟数发送企业微信
        private readonly int PadNotice = Convert.ToInt32(UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["PadNotice"])));
        //预约天数限制
        private readonly int MeetingOrderDays = Convert.ToInt32(UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MeetingOrderDays"])));
        private readonly int ExchangeOn = Convert.ToInt32(UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ExchangeOn"])));

        public List<CRoomInfo> GetAllGMSRoom()
        {
            var res = dal.GetAllGMSRoom(out string strError);
            var lis = TableToList.ToList<CRoomInfo>(res.Result);
            return lis;
        }

        ////预约周期限制
        //private readonly int cycle = Convert.ToInt32(UCommonWork.Common.Commons.MD5DecodeString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["cycle"])));

        public ConferenceRoomService(string Operator, string OperaIP)
        {
            this.Operator = Operator;
            this.OperaIP = OperaIP;
            if (dal == null)
            {
                lock (this.OperaIP)
                {
                    if (dal == null)
                    {
                        dal = DalFactory.DalFactory.GetMeetingDaL();
                    }
                }
            }

            if (setdal == null)
            {
                lock (this.OperaIP)
                {
                    if (setdal == null)
                    {
                        setdal = DalFactory.DalFactory.GetSettingDaL();
                    }
                }
            }
            if (userdal == null)
            {
                lock (this.OperaIP)
                {
                    if (userdal == null)
                    {
                        userdal = DalFactory.DalFactory.GetUserDAL();
                    }
                }
            }
            if (upLoadDal == null)
            {
                lock (this.OperaIP)
                {
                    if (upLoadDal == null)
                    {
                        upLoadDal = DalFactory.DalFactory.GetUpLoadDal();
                    }
                }
            }
            if (exchangeToDbDal == null)
            {
                lock (this.OperaIP)
                {
                    if (exchangeToDbDal == null)
                    {
                        exchangeToDbDal = DalFactory.DalFactory.GetExchangeToDbDal();
                    }
                }
            }

        }

        private UEntity.LogEntity.ELogRecordEntity LogEntity = new UEntity.LogEntity.ELogRecordEntity();

        /// <summary>
        /// 添加会议室
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> AddMeetingRoom(MeetingRoomOrder entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.AddMeetingRoom";
            LogEntity.OperateObject = "AddMeetingRoom";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingRoomOrder>(entity);
            PageList<MeetingRoomInfo> list = new PageList<MeetingRoomInfo>();
            try
            {
                list = await GetCRoomByRID(new RoomQuery()
                {
                    RID = entity.RID,
                    pageIndex = 1,
                    pageSize = 10000,
                });
                foreach (var item in list.List)
                {
                    if (item.ConferenceName.Trim() == entity.ConferenceName.Trim())
                    {
                        bResult = false;
                        strError = "该区域下存在同名的会议室";
                        return (bResult, strError);
                    }
                }

                bResult = await dal.AddMeetingRoom(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
                //  CMSHttpHelper HTTP = new CMSHttpHelper();
                // HTTP.ResetPasscodeAdd(PassCode);
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("AddMeetingRoom Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 根据会议室ID获取会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MeetingRoomOrder> GetMeetingRoomByID(MeetingRoomQuery query)
        {
            MeetingRoomOrder meetingRoomOrder = new MeetingRoomOrder();
            List<MeetingRoomOrder> list = new List<MeetingRoomOrder>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetMeetingRoomBylID";
            LogEntity.OperateObject = "GetMeetingRoomByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingRoomQuery>(query);
            try
            {
                var res = await dal.GetMeetingRoomByID(query, out strError);

                if (strError == "")
                {
                    list = TableToList.ToList<MeetingRoomOrder>(res);
                    meetingRoomOrder = list[0];

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetMeetingRoomByID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return meetingRoomOrder;
        }

        /// <summary>
        /// 会议室(编辑)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateMeetingRoomByID(MeetingRoomOrder entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateMeetingRoomByID";
            LogEntity.OperateObject = "UpdateMeetingRoomByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingRoomOrder>(entity);
            try
            {


                bResult = await dal.UpdateMeetingRoomByID(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }


            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateMeetingRoomByID Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }
        public async Task<(bool, string)> UpdatePassCode(MeetingRoomOrder entity)
        {
            string strError = "";
            bool bResult = true;
            try
            {
                CMSHttpHelper cMS = new CMSHttpHelper();
                cMS.SetPassCode(new CRoomInfo()
                {
                    CMSGuid = entity.CmsGuid,
                    ID = int.Parse(entity.CRoomID),
                    passcode = entity.Passcode
                }, out strError);

                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                strError = string.Format("UpdatePasscode Exception:{0}", ex.ToString());

            }

            return (bResult, strError);
        }


        /// <summary>
        /// 删除会议室
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> DeleteMeetingRoom(MeetingRoomQuery entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.DeleteMeetingRoom";
            LogEntity.OperateObject = "DeleteMeetingRoom";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingRoomQuery>(entity);
            try
            {
                bResult = await dal.DeleteMeetingRoom(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("DeleteMeetingRoom Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        /// 会议预约
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string, List<int>, bool, bool, int)> MeetingOrder(LoginUser user, MeetingOrder entity)
        {
            string strError = "";
            string strError1 = "";
            string strError2 = "";
            string strError3 = "";
            string strError4 = "";
            string strError5 = "";
            string strError6 = "";
            string strError7 = "";
            int procInstID = 0;
            List<int> meetIDs = new List<int>();
            bool bResult = true;
            bool IsSendWX = false;
            bool IsSendBPM = false;
            int CycleMeetType = 0;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.MeetingOrder";
            LogEntity.OperateObject = "MeetingOrder";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {

                entity.RID = Convert.ToInt32(user.OrgId);
                // 会议室
                string[] CRoomIDs = entity.CRoomIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                //string[] CRoomTypes = entity.CRoomTypes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);
                var res1 = DateTime.TryParse(entity.Date + " " + entity.End, out DateTime resultt);
                if (res1)
                {
                    entity.EndTime = resultt;
                }
                else
                {
                    entity.EndTime = DateTime.Now.AddDays(1).Date;
                }

                SettingSystem systemstart = new SettingSystem();
                systemstart = setting.GetSettingSystem().Result.FirstOrDefault();

                if (entity.BeginTime > DateTime.Now.AddMinutes(PadNotice))
                {
                    IsSendWX = true;
                }
                if (entity.BeginTime <= DateTime.Now || entity.EndTime <= DateTime.Now)
                {
                    bResult = false;
                    strError1 = "预约会议的时间不能小于当前时间";
                }
                if (entity.EndTime <= entity.BeginTime)
                {
                    bResult = false;
                    strError1 = "预约会议的时间有误，请重新选择时间";
                }

                //会议预约是否有时间冲突
                var list = await GetRoomInfoByTime(new CRoomTimeQuery()
                {
                    CRoomIDs = entity.CRoomIDs,
                    BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin),
                    EndTime = entity.EndTime

                });
                if (list != null && list.Count > 0)
                {
                    strError2 += "您预约的会议与以下会议室时间冲突:";
                    bResult = false;
                    foreach (var item in list)
                    {
                        strError2 += item.ConferenceName + "，";
                    }

                }
                List<int> types = new List<int>();
                List<int> StrategyStates = new List<int>();
                foreach (var room in CRoomIDs)
                {
                    ConferenceRoom conference = new ConferenceRoom();
                    conference.ID = Convert.ToInt32(room);
                    var type = TableToList.ToList<MeetingRoomInfo>(dal.GetCRoomTypeByID(conference, out strError).Result).FirstOrDefault();
                    types.Add(type.ConferenceType);
                    StrategyStates.Add(type.StrategyState);
                }
                if (types.Count > 0)
                {
                    for (int i = 1; i < types.Count; i++)
                    {
                        if (types[0] != types[i])
                        {
                            bResult = false;
                            strError7 = "会议室类型不一致";
                            break;
                        }
                    }
                }
                if (StrategyStates.Count > 0)
                {
                    for (int i = 0; i < StrategyStates.Count; i++)
                    {
                        if (StrategyStates[i] == 2)
                        {
                            entity.StrategyState = 2;
                            break;
                        }
                        else
                        {
                            entity.StrategyState = 1;
                        }
                    }
                }
                if (entity.StrategyState == 2)
                {
                    entity.ToDayEnd = entity.EndTime.Date.AddDays(1);
                }
                else
                {
                    entity.ToDayEnd = entity.EndTime;
                }
                //会议室密码
                entity.ConferenceType = types[0];

                //for (int i = 0; i < CRoomIDs.Length; i++)
                //{
                //    var password = GetPassWord();
                //    Thread.Sleep(200);
                //    entity.PassWords += password + ",";
                //}

                //系统管理员无需审批
                if (user.IsAdmin != 3)
                {
                    //for (int i = 0; i < CRoomIDs.Length; i++)
                    //{
                    //    var CRoomID = Convert.ToInt32(CRoomIDs[i]);
                    //    var CRoom = await dal.GetCRoomApproval(new ConferenceRoom()
                    //    {
                    //        ID = CRoomID,


                    //    }, out strError);
                    //    if (CRoom.Rows.Count > 0)
                    //    {
                    //        entity.State = 4;
                    //        IsSendBPM = true;
                    //        break;
                    //    }
                    //}
                }
                else
                {
                    IsSendBPM = false;
                }

                if (entity.CycleType == 0)//预约会议（单次）
                {
                    entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);

                    if (DateTime.TryParse(entity.Date + " " + entity.End, out resultt))
                    {
                        entity.EndTime = resultt;
                    }
                    else
                    {
                        entity.EndTime = DateTime.Now.AddDays(1).Date;
                    }
                    //       entity.EndTime = Convert.ToDateTime(entity.Date + " " + entity.End);


                    if (user.IsAdmin == 0 || user.IsAdmin == 1)
                    {
                        if (entity.BeginTime >= DateTime.Now.Date.AddDays(MeetingOrderDays))
                        {
                            bResult = false;
                            strError2 = "不能预约超过" + (MeetingOrderDays - 1) + "天的会议";
                        }
                        else if (entity.BeginTime >= DateTime.Now.AddDays(MeetingOrderDays).AddDays(-1).Date)
                        {


                            if (DateTime.Now.Hour < systemstart.SubscribeBegin || DateTime.Now.Hour >= systemstart.SubscribeEnd)
                            {
                                strError = "请在" + systemstart.SubscribeBegin + "-" + systemstart.SubscribeEnd + "点之间进行会议室预约！";
                                return (false, strError, meetIDs, false, false, 0);
                            }
                        }
                    }


                    if (user.IsAdmin == 2)
                    {
                        if (entity.BeginTime >= DateTime.Now.Date.AddDays(MeetingOrderDays))
                        {
                            var userRoom = await dal.GetCRoomByRID(new RoomQuery()
                            {
                                RID = entity.UserRID,
                                Key = "",
                                pageIndex = 1,
                                pageSize = 100000,
                            }, out strError);
                            var userRoomList = TableToList.ToList<MeetingRoomInfo>(userRoom.Item1);
                            var items = "";
                            foreach (var item in userRoomList)
                            {
                                items += item.ID.ToString();
                            }
                            for (int i = 0; i < CRoomIDs.Length; i++)
                            {
                                var CRoomID = Convert.ToInt32(CRoomIDs[i]);
                                if (!items.Contains(CRoomID.ToString()))
                                {
                                    return (false, "您预约的会议信息中,有会议室不在您的城市管理中", meetIDs, false, false, 0);
                                }
                            }
                        }

                    }

                    //单人每月100积分，预约一次会议5分
                    UserQuery userQuery = new UserQuery();
                    userQuery.ID = entity.CreatorID;
                    var userIntegral = TableToList.ToList<UserIntegral>(userdal.GetUserIntegral(userQuery, out strError).Result.Item1);
                    if (user.IsAdmin == 0)
                    {
                        //会议时长是否超出系统配置单个会议时长
                        var res = setdal.GetMeetingTimeLimit(out strError);

                        if (entity.TimeLength > res.Result.CTimeLimit * 60)
                        {
                            bResult = false;
                            strError3 = "预约会议的时长不能超过" + res.Result.CTimeLimit + "小时";

                        }

                        if (userIntegral[0].Integral <= 0)
                        {
                            bResult = false;
                            strError4 += "每预约一次会议会扣除5积分，您的本月积分已使用完毕（每月100积分）";

                        }
                        //单人每天预定会议室不能超过两次
                        var dt = await dal.GetMeetingCountByUserID(new UserIDAndTime()
                        {
                            UserID = entity.CreatorID,

                        }, out strError);
                        if (dt.Rows.Count >= FrequencyLimit)
                        {
                            bResult = false;
                            strError5 += "单人每天预定会议室不能超过" + FrequencyLimit + "次，详见【会议须知】";
                        }
                        //创建人员是否有会议纪要没有上传（48小时内）
                        //var checkMinutes = await CheckMinutes(new CheckMinutesQuery()
                        //{
                        //    UserID = entity.CreatorID,
                        //    CheckTime = DateTime.Now.AddHours(-MinutesHours),

                        //});
                        //if (checkMinutes != null && checkMinutes.Count > 0)
                        //{
                        //    bResult = false;
                        //    foreach (var item in checkMinutes)
                        //    {
                        //        strError6 += "会议名称为：" + item.ConferenceTheme + ",";
                        //    }
                        //    strError6 += "的会议纪要在48小时内没有上传";

                        //}
                    }


                }
                else
                {
                    if (user.IsAdmin == 2)
                    {

                        var userRoom = await dal.GetCRoomByRID(new RoomQuery()
                        {
                            RID = entity.UserRID,
                            Key = "",
                            pageIndex = 1,
                            pageSize = 100000,
                        }, out strError);
                        var userRoomList = TableToList.ToList<MeetingRoomInfo>(userRoom.Item1);
                        var items = "";
                        foreach (var item in userRoomList)
                        {
                            items += item.ID.ToString();

                        }
                        for (int i = 0; i < CRoomIDs.Length; i++)
                        {
                            var CRoomID = Convert.ToInt32(CRoomIDs[i]);
                            if (!items.Contains(CRoomID.ToString()))
                            {
                                return (false, "您预约的周期会议信息中有会议室不在您的城市管理之内", meetIDs, false, false, 0);
                            }
                        }

                    }

                }

                strError = strError + strError1 + strError2 + strError3 + strError4 + strError5 + strError6 + strError7;

                if (bResult == false)
                {
                    return (bResult, strError, meetIDs, IsSendWX, IsSendBPM, CycleMeetType);
                }



                //string[] arrStr = entity.CRoomTypes.Split(',');



                entity.CycleMeetGuid = Guid.NewGuid().ToString();
                //周期会议     都是预约12次会议。

                if (entity.CycleType == 0)//预约会议（单次）
                {
                    CycleMeetType = 0;
                    entity.CycleMeetType = 0;
                    if (ExchangeOn == 1)
                    {
                        ExChangeHelper helper = new ExChangeHelper();
                        var address = exchangeToDbDal.GetUserEmail(entity.CreatorID);
                        var ap = DbToExchangeService.getEmailEntity(entity);

                        var o365 = new O365Helper();
                        var itemList = o365.SendMeetingReady(entity);
                        //  var itemID = helper.SendMeeting(ap, address.Mail, out string itemId);
                        if (itemList.Count > 0)
                        {
                            var insertItem = itemList.Where(i => i.IsAuto == false).FirstOrDefault();
                            entity.ExchangeItemId = insertItem.ItemId;
                            entity.itemId = insertItem.ItemId;
                            (bResult, procInstID) = dal.MeetingOrder(entity, out strError).Result;
                            foreach (var item in itemList)
                            {
                                item.meetId = procInstID;
                                var result = dal.InsertMeetingItemId(item, out strError).Result;

                            }

                            if (!bResult)
                            {
                                LogEntity.OperateResult = "Fail";
                                bResult = false;
                            }
                        }
                        else
                        {
                            LogEntity.OperateResult = "Exchange Id 为空 ";
                            bResult = false;
                        }
                    }
                    else
                    {
                        (bResult, procInstID) = dal.MeetingOrder(entity, out strError).Result;
                        meetIDs.Add(procInstID);
                        if (!bResult)
                        {
                            LogEntity.OperateResult = "Fail";
                            bResult = false;
                        }
                    }
                }
                //else if (entity.CycleType == 1)  //预约会议室（每周）
                //{
                //    CycleMeetType = 1;
                //    entity.CycleMeetType = 1;
                //    while (Convert.ToDateTime(entity.Date) <= Convert.ToDateTime(entity.EndDate))
                //    {
                //        //会议预约是否有时间冲突
                //        list = await GetRoomInfoByTime(new CRoomTimeQuery()
                //        {
                //            CRoomIDs = entity.CRoomIDs,
                //            BeginTime = entity.BeginTime,
                //            EndTime = entity.EndTime

                //        });
                //        if (list != null && list.Count > 0)
                //        {

                //            bResult = false;
                //            strError = "您预约的周期会议的会议室与以下会议室时间冲突：时间：" + entity.BeginTime + "-" + entity.EndTime;
                //            foreach (var item in list)
                //            {

                //                strError2 = item.ConferenceName + "，";
                //            }
                //            if (bResult == false)
                //            {
                //                return (bResult, strError, meetIDs, IsSendWX, IsSendBPM, CycleMeetType);
                //            }
                //        }
                //        while (Convert.ToDateTime(entity.Date) <= Convert.ToDateTime(entity.EndDate))
                //        {
                //            (bResult, procInstID) = dal.MeetingOrder(entity, out strError).Result;
                //            meetIDs.Add(procInstID);
                //            if (!bResult)
                //            {
                //                LogEntity.OperateResult = "Fail";
                //                bResult = false;
                //            }
                //            entity.BeginTime = entity.BeginTime.AddDays(7);
                //            entity.EndTime = entity.EndTime.AddDays(7);
                //            entity.Date = Convert.ToDateTime(entity.Date).AddDays(7).ToString();
                //        }
                //        //entity.Date = Convert.ToDateTime(entity.Date).AddDays(7).ToString();
                //    }





                //}
                //else if (entity.CycleType == 2)//预约会议室（双周）
                //{
                //    CycleMeetType = 2;
                //    entity.CycleMeetType = 2;
                //    while (Convert.ToDateTime(entity.Date) <= Convert.ToDateTime(entity.EndDate))
                //    {
                //        //会议预约是否有时间冲突
                //        list = await GetRoomInfoByTime(new CRoomTimeQuery()
                //        {
                //            CRoomIDs = entity.CRoomIDs,
                //            BeginTime = entity.BeginTime,
                //            EndTime = entity.EndTime

                //        });
                //        if (list != null && list.Count > 0)
                //        {

                //            bResult = false;
                //            strError = "您预约的周期会议的会议室与以下会议室时间冲突：时间：" + entity.BeginTime + "-" + entity.EndTime;
                //            foreach (var item in list)
                //            {

                //                strError2 = item.ConferenceName + "，";
                //            }
                //            if (bResult == false)
                //            {
                //                return (bResult, strError, meetIDs, IsSendWX, IsSendBPM, CycleMeetType);
                //            }
                //        }
                //        while (Convert.ToDateTime(entity.Date) <= Convert.ToDateTime(entity.EndDate))
                //        {
                //            (bResult, procInstID) = dal.MeetingOrder(entity, out strError).Result;
                //            meetIDs.Add(procInstID);
                //            if (!bResult)
                //            {
                //                LogEntity.OperateResult = "Fail";
                //                bResult = false;
                //            }
                //            entity.BeginTime = entity.BeginTime.AddDays(14);
                //            entity.EndTime = entity.EndTime.AddDays(14);
                //            entity.Date = Convert.ToDateTime(entity.Date).AddDays(14).ToString();
                //        }
                //        //entity.Date = Convert.ToDateTime(entity.Date).AddDays(14).ToString();
                //    }



                //}
                //else if (entity.CycleType == 3)//预约会议室（每月）
                //{
                //    CycleMeetType = 3;
                //    entity.CycleMeetType = 3;
                //    while (Convert.ToDateTime(entity.Date) <= Convert.ToDateTime(entity.EndDate))
                //    {
                //        //会议预约是否有时间冲突
                //        list = await GetRoomInfoByTime(new CRoomTimeQuery()
                //        {
                //            CRoomIDs = entity.CRoomIDs,
                //            BeginTime = entity.BeginTime,
                //            EndTime = entity.EndTime

                //        });
                //        if (list != null && list.Count > 0)
                //        {

                //            bResult = false;
                //            strError = "您预约的周期会议的会议室与以下会议室时间冲突：时间：" + entity.BeginTime + "-" + entity.EndTime;
                //            foreach (var item in list)
                //            {

                //                strError2 = item.ConferenceName + "，";
                //            }
                //            if (bResult == false)
                //            {
                //                return (bResult, strError, meetIDs, IsSendWX, IsSendBPM, CycleMeetType);
                //            }
                //        }

                //        while (Convert.ToDateTime(entity.Date) <= Convert.ToDateTime(entity.EndDate))
                //        {
                //            (bResult, procInstID) = dal.MeetingOrder(entity, out strError).Result;
                //            meetIDs.Add(procInstID);
                //            if (!bResult)
                //            {
                //                LogEntity.OperateResult = "Fail";
                //                bResult = false;
                //            }
                //            entity.BeginTime = entity.BeginTime.AddMonths(1);
                //            entity.EndTime = entity.EndTime.AddMonths(1);
                //            entity.Date = Convert.ToDateTime(entity.Date).AddMonths(1).ToString();
                //        }
                //        //entity.Date = Convert.ToDateTime(entity.Date).AddMonths(1).ToString();
                //    }



                //}




            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("MeetingOrder Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError, meetIDs, IsSendWX, IsSendBPM, CycleMeetType);
        }

        public string GetPassWord()
        {

            long tick = DateTime.Now.Ticks;
            Random rd = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
            //Random rd = new Random();
            int num = rd.Next(100000, 1000000);
            var password = num.ToString();
            dal.GheckPassWord(password, DateTime.Today, out int ReturnValue);
            if (ReturnValue > 0)
            {
                password = GetPassWord();
            }

            return Convert.ToString(password);
        }

        /// <summary>
        /// 会议信息(编辑)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string, int, bool, bool)> UpdateConferenceInfo(LoginUser user, MeetingOrder entity)
        {
            string strError = "";
            string strError1 = "";
            string strError2 = "";
            string strError3 = "";
            string strError4 = "";
            string strError5 = "";
            bool bResult = true;
            bool IsSendWX = false;
            bool IsSendBPM = false;

            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateConferenceInfo";
            LogEntity.OperateObject = "UpdateConferenceInfo";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {

                string[] CRoomIDs = entity.CRoomIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);
                entity.EndTime = Convert.ToDateTime(entity.Date + " " + entity.End);
                SettingSystem systemstart = new SettingSystem();
                systemstart = setting.GetSettingSystem().Result.FirstOrDefault();
                //if (DateTime.Now.Hour < systemstart.SubscribeBegin || DateTime.Now.Hour >= systemstart.SubscribeEnd)
                //{
                //    strError = "请在" + systemstart.SubscribeBegin + "-" + systemstart.SubscribeEnd + "点之间进行会议室预约！";
                //    return (false, strError, 0, false, false);
                //}
                if (entity.BeginTime.Hour < systemstart.SubscribeBegin || entity.BeginTime.Hour >= systemstart.SubscribeEnd)
                {
                    strError = "请预约" + systemstart.SubscribeBegin + "-" + systemstart.SubscribeEnd + "点之间的会议室！";
                    return (false, strError, 0, false, false);
                }
                if (entity.EndTime.Hour < systemstart.SubscribeBegin || entity.EndTime.Hour >= systemstart.SubscribeEnd)
                {
                    strError = "请预约" + systemstart.SubscribeBegin + "-" + systemstart.SubscribeEnd + "点之间的会议室！";
                    return (false, strError, 0, false, false);
                }


                List<int> types = new List<int>();
                List<int> StrategyStates = new List<int>();
                foreach (var room in CRoomIDs)
                {
                    ConferenceRoom conference = new ConferenceRoom();
                    conference.ID = Convert.ToInt32(room);
                    var type = TableToList.ToList<MeetingRoomInfo>(dal.GetCRoomTypeByID(conference, out strError).Result).FirstOrDefault();
                    types.Add(type.ConferenceType);
                    StrategyStates.Add(type.StrategyState);
                }
                if (types.Count > 1)
                {
                    for (int i = 1; i < types.Count; i++)
                    {
                        if (types[0] != types[i])
                        {
                            strError5 = "会议室类型不一致";
                            break;
                        }
                    }
                }
                if (StrategyStates.Count > 0)
                {
                    for (int i = 0; i < StrategyStates.Count; i++)
                    {
                        if (StrategyStates[i] == 2)
                        {
                            entity.StrategyState = 2;
                            break;
                        }
                        else
                        {
                            entity.StrategyState = 1;
                        }
                    }
                }
                if (entity.StrategyState == 2)
                {
                    entity.ToDayEnd = entity.EndTime.Date.AddDays(1);
                }
                else
                {
                    entity.ToDayEnd = entity.EndTime;
                }
                //会议室密码
                //会议室密码
                entity.ConferenceType = types[0];

                for (int i = 0; i < CRoomIDs.Length; i++)
                {
                    var password = GetPassWord();
                    entity.PassWords += password + ",";
                }
                if (entity.BeginTime > DateTime.Now.AddMinutes(PadNotice))
                {
                    IsSendWX = true;
                }
                if (entity.BeginTime <= DateTime.Now || entity.EndTime <= DateTime.Now)
                {
                    bResult = false;
                    strError1 = "预约会议的时间不能小于当前时间";
                }
                if (entity.EndTime <= entity.BeginTime)
                {
                    bResult = false;
                    strError1 = "预约会议的时间有误，请重新选择时间";
                }
                if (user.IsAdmin == 0 || user.IsAdmin == 1)
                {
                    if (entity.BeginTime >= DateTime.Now.Date.AddDays(MeetingOrderDays))
                    {
                        bResult = false;
                        strError2 = "不能预约超过" + (MeetingOrderDays - 1) + "天的会议室";
                    }
                    else if (entity.BeginTime >= DateTime.Now.AddDays(MeetingOrderDays).AddDays(-1).Date)
                    {


                        if (DateTime.Now.Hour < systemstart.SubscribeBegin || DateTime.Now.Hour >= systemstart.SubscribeEnd)
                        {
                            strError = "请在" + systemstart.SubscribeBegin + "-" + systemstart.SubscribeEnd + "点之间进行会议室预约！";
                            return (false, strError, 0, false, false);
                        }
                    }
                }
                else if (user.IsAdmin == 2)
                {
                    if (entity.BeginTime >= DateTime.Now.Date.AddDays(MeetingOrderDays))
                    {
                        var userRoom = await dal.GetCRoomByRID(new RoomQuery()
                        {
                            RID = entity.UserRID,
                            Key = "",
                            pageIndex = 1,
                            pageSize = 100000,
                        }, out strError);
                        var userRoomList = TableToList.ToList<MeetingRoomInfo>(userRoom.Item1);
                        var items = "";
                        foreach (var item in userRoomList)
                        {
                            items += item.ID.ToString();
                        }
                        for (int i = 0; i < CRoomIDs.Length; i++)
                        {
                            var CRoomID = Convert.ToInt32(CRoomIDs[i]);
                            if (!items.Contains(CRoomID.ToString()))
                            {
                                return (false, "您所选择的会议室中有不能预约超过" + (MeetingOrderDays - 1) + "天的会议室(不在您的城市管理中)", 0, false, false);
                            }
                        }
                    }

                }
                if (user.IsAdmin == 0)
                {
                    //会议时长是否超出系统配置单个会议时长
                    var res = setdal.GetMeetingTimeLimit(out strError);

                    if (entity.TimeLength > res.Result.CTimeLimit * 60)
                    {
                        bResult = false;
                        strError3 = "预约会议的时长不能超过" + res.Result.CTimeLimit + "小时";

                    }
                }




                //会议预约是否有时间冲突
                var list = await GetRoomInfoByTime(new CRoomTimeQuery()
                {
                    CInfoID = entity.CInfoID,
                    CRoomIDs = entity.CRoomIDs,
                    BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin),
                    EndTime = Convert.ToDateTime(entity.Date + " " + entity.End),

                });
                if (list != null && list.Count > 0)
                {
                    bResult = false;
                    foreach (var item in list)
                    {
                        strError4 += item.ConferenceName + "时间冲突，";
                    }

                }


                strError = strError1 + strError2 + strError3 + strError4 + strError5;
                if (bResult == false)
                {
                    return (bResult, strError, entity.ID, false, false);
                }

                //string[] CRoomIDs = entity.CRoomIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < CRoomIDs.Length; i++)
                {
                    var CRoom = dal.GetCRoomApproval(new ConferenceRoom()
                    {
                        ID = Convert.ToInt32(CRoomIDs[i]),


                    }, out strError);
                    if (CRoom.Result.Rows.Count > 0)
                    {
                        entity.State = 4;
                        IsSendBPM = true;
                        break;
                    }
                }
                for (int i = 0; i < CRoomIDs.Length; i++)
                {
                    var CRoomID = Convert.ToInt32(CRoomIDs[i]);
                    var Room = await GetMeetingRoomByID(new MeetingRoomQuery()
                    {
                        ID = CRoomID,
                    });
                    if (Room.IsSignOn == true)
                    {
                        entity.IsSignIn = 0;
                        break;
                    }
                }
                if (ExchangeOn == 1)
                {


                    var address = exchangeToDbDal.GetUserEmail(entity.CreatorID);
                    var ap = DbToExchangeService.getEmailEntity(entity);
                    var meetList = exchangeToDbDal.GetMeetExchangeItemIdByID(entity.CInfoID);
                    foreach (var meet in meetList)
                    {
                        ExChangeHelper helper = new ExChangeHelper(5, meet.ewsAccount, meet.ewsPwd, meet.ewsUrl);
                        ap.OldStart = meet.BeginTime;
                        ap.OldEnd = meet.EndTime;
                        ap.ID = meet.ExchangeItemId;
                        entity.ExchangeItemId = ap.ID;
                        if (meet.IsAuto)
                        {
                            bResult = helper.UpdateMeeting(ap, meet.OrderUser, true, out strError);
                        }
                        else
                        {
                            bResult = helper.UpdateMeeting(ap, address.Mail, false, out strError);
                        }

                    }
                    if (bResult)
                    {
                        bResult = await dal.UpdateMeetingInfoByID(entity, out strError);
                    }

                    else
                    {
                        LogEntity.OperateResult = "exchange 更新 Fail";
                        bResult = false;
                    }
                }
                else {
                    bResult = await dal.UpdateMeetingInfoByID(entity, out strError);
                    if (!bResult)
                    {
                        LogEntity.OperateResult = "Fail";
                        bResult = false;
                    }
                }
             







            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateConferenceInfo Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError, entity.ID, IsSendWX, IsSendBPM);
        }
        public void SendWxMssage(CRoomPadQuery obj)
        {
            var weChat = new WeChatHelper();
            weChat.SendWxMssage(obj);
        }

        /// <summary>
        /// 根据会议ID获取会议纪要
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MinutesInfoSingle> GetCInfoMinutesByID(CInfoQuery query)
        {
            MinutesInfoSingle meetingInfoSingle = new MinutesInfoSingle();
            List<MinutesInfoSingle> list = new List<MinutesInfoSingle>();
            List<Files> files = new List<Files>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCInfoMinutesByID";
            LogEntity.OperateObject = "GetCInfoMinutesByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var res = await dal.GetCInfoMinutesByID(query, out strError);

                if (strError == "")
                {
                    list = TableToList.ToList<MinutesInfoSingle>(res.Item1);
                    files = TableToList.ToList<Files>(res.Item2);

                    meetingInfoSingle = list[0];
                    meetingInfoSingle.files = files;
                    meetingInfoSingle.date = Convert.ToDateTime(meetingInfoSingle.BeginTime).ToString("yyyy-MM-dd");
                    meetingInfoSingle.Begin = Convert.ToDateTime(meetingInfoSingle.BeginTime).ToString("HH:mm");
                    meetingInfoSingle.End = Convert.ToDateTime(meetingInfoSingle.EndTime).ToString("HH:mm");
                    meetingInfoSingle.CRooms = meetingInfoSingle.CRoom + "/" + meetingInfoSingle.CRooms;
                    meetingInfoSingle.CRooms = meetingInfoSingle.CRooms.Substring(0, meetingInfoSingle.CRooms.Length - 1);
                    meetingInfoSingle.CRoomIDs = meetingInfoSingle.CRoomID + "," + meetingInfoSingle.CRoomIDs;
                    if (meetingInfoSingle.ConferenceType == 0)
                    {
                        meetingInfoSingle.ConferenceType = 1;
                    }
                    //switch (meetingInfoSingle.ConferenceType)
                    //{
                    //    case 1: meetingInfoSingle.ConferenceTypeName = "专题会议"; break;
                    //    case 2: meetingInfoSingle.ConferenceTypeName = "面试"; break;
                    //    case 3: meetingInfoSingle.ConferenceTypeName = "培训"; break;
                    //    case 4: meetingInfoSingle.ConferenceTypeName = "客户接待"; break;
                    //    case 5: meetingInfoSingle.ConferenceTypeName = "访谈交流"; break;
                    //    case 6: meetingInfoSingle.ConferenceTypeName = "外部主场"; break;
                    //    case 7: meetingInfoSingle.ConferenceTypeName = "分会场参会"; break;
                    //    case 8: meetingInfoSingle.ConferenceTypeName = "其他类型"; break;
                    //    default: meetingInfoSingle.ConferenceTypeName = "请选择会议类型"; break;
                    //}
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCInfoMinutesByID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return meetingInfoSingle;
        }

        /// <summary>
        /// 会议纪要(手动创建)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string, int)> MinutesOrder(MeetingOrder entity)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            string url = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.MinutesOrder";
            LogEntity.OperateObject = "MinutesOrder";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {


                if (entity.IsMinutesApproval == true)
                {
                    if ((DateTime.Now - entity.BeginTime).Hours > MinutesHours)
                    {
                        entity.IsSubmitOnTime = false;
                    }
                    else
                    {
                        entity.IsSubmitOnTime = true;
                    }
                }

                var (bResult, id) = await dal.MinutesOrder(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    res = false;
                }
                idd = id;

            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("MinutesOrder Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }

        /// <summary>
        /// 会议纪要(编辑)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateConferenceMinutes(MeetingOrder entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateConferenceMinutes";
            LogEntity.OperateObject = "UpdateConferenceMinutes";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {
                entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);
                entity.EndTime = Convert.ToDateTime(entity.Date + " " + entity.End);

                if ((DateTime.Now - entity.EndTime).Hours > MinutesHours)
                {
                    entity.IsSubmitOnTime = false;
                }
                else
                {
                    entity.IsSubmitOnTime = true;
                }



                bResult = await dal.UpdateConferenceMinutes(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }


            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateConferenceMinutes Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 根据查询关键字获取所有会议纪要信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MinutesList>> GetCInfoMinutesList(CInfoQuery query)
        {

            PageList<MinutesList> list = new PageList<MinutesList>();
            List<MinutesList> minutesList = new List<MinutesList>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCInfoMinutesList";
            LogEntity.OperateObject = "GetCInfoMinutesList";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var res = await dal.GetCInfoMinutesList(query, out strError);
                //TODO
                if (strError == "")
                {
                    minutesList = TableToList.ToList<MinutesList>(res.Item1);
                    foreach (var item in minutesList)
                    {
                        switch (item.ConferenceType)
                        {
                            case 1: item.MeetingType = "专题会议"; break;
                            case 2: item.MeetingType = "面试"; break;
                            case 3: item.MeetingType = "培训"; break;
                            case 4: item.MeetingType = "客户接待"; break;
                            case 5: item.MeetingType = "访谈交流"; break;
                            case 6: item.MeetingType = "外部主场"; break;
                            case 7: item.MeetingType = "分会场参会"; break;
                            case 8: item.MeetingType = "其他类型"; break;
                            default: item.MeetingType = "专题会议"; break;
                        }
                        if (!string.IsNullOrWhiteSpace(item.procInstID))
                        {
                            if (item.procInstID == "0")
                            {
                                item.MinutesState = 4;
                            }
                            else
                            {
                                if (item.MinutesState == 3)
                                {
                                    item.MinutesState = 5;
                                }
                            }
                        }
                        if (item.MinutesState == 0) //未审批
                        {
                            item.Oprate = "上传";
                            item.State = "未上传";
                        }
                        else if (item.MinutesState == 1)//审批中
                        {
                            item.Oprate = "查看";
                            item.State = "审批中";
                        }
                        else if (item.MinutesState == 2)//已完成
                        {
                            item.Oprate = "查看";
                            item.State = "已完成";
                        }
                        else if (item.MinutesState == 3)
                        {
                            item.Oprate = "编辑";
                            item.State = "未通过";
                        }
                        else if (item.MinutesState == 4)
                        {
                            item.Oprate = "查看";
                            item.State = "待发起";
                        }
                        else if (item.MinutesState == 5)
                        {
                            item.Oprate = "编辑";
                            item.State = "再次发起";
                        }
                        if (!string.IsNullOrWhiteSpace(item.procURL))
                        {
                            item.procURL = Uri.UnescapeDataString(item.procURL);
                        }

                        item.date = Convert.ToDateTime(item.BeginTime).ToString("yyyy-MM-dd");
                        item.Begin = Convert.ToDateTime(item.BeginTime).ToString("HH:mm");
                        item.End = Convert.ToDateTime(item.EndTime).ToString("HH:mm");
                    }
                    list.List = minutesList;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCInfoMinutesList Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        /// <summary>
        /// 根据查询关键字获取组织所有会议纪要信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MinutesList>> GetOrgMinutes(CInfoQuery query)
        {

            PageList<MinutesList> list = new PageList<MinutesList>();
            List<MinutesList> minutesList = new List<MinutesList>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCInfoMinutesList";
            LogEntity.OperateObject = "GetCInfoMinutesList";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var res = await dal.GetOrgMinutes(query, out strError);
                //TODO
                if (strError == "")
                {
                    minutesList = TableToList.ToList<MinutesList>(res.Item1);
                    foreach (var item in minutesList)
                    {
                        switch (item.ConferenceType)
                        {
                            case 1: item.MeetingType = "专题会议"; break;
                            case 2: item.MeetingType = "面试"; break;
                            case 3: item.MeetingType = "培训"; break;
                            case 4: item.MeetingType = "客户接待"; break;
                            case 5: item.MeetingType = "访谈交流"; break;
                            case 6: item.MeetingType = "外部主场"; break;
                            case 7: item.MeetingType = "分会场参会"; break;
                            case 8: item.MeetingType = "其他类型"; break;
                            default: item.MeetingType = "专题会议"; break;
                        }


                        item.Oprate = "查看";
                        item.State = "已完成";


                        item.date = Convert.ToDateTime(item.BeginTime).ToString("yyyy-MM-dd");
                        item.Begin = Convert.ToDateTime(item.BeginTime).ToString("HH:mm");
                        item.End = Convert.ToDateTime(item.EndTime).ToString("HH:mm");
                      
                    }
                    list.List = minutesList;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCInfoMinutesList Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 获取会议室及相关会议信息（首页预约展示）
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MeetAndRoomInfo> GetMeetRoomAndInfo(RoomQuery query)
        {
            MeetAndRoomInfo list = new MeetAndRoomInfo();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetMeetRoomAndInfo";
            LogEntity.OperateObject = "GetMeetRoomAndInfo";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                query.BeginTime = Convert.ToDateTime(query.Date + " 00:00:01");
                query.EndTime = Convert.ToDateTime(query.Date + " 23:59:59");

                if (query.RIDs.Count > 0 && query.RIDs != null)
                {
                    foreach (var item in query.RIDs)
                    {
                        query.RID = item;
                        var res = await dal.GetCRoomAndCInfo(query, out strError);
                        if (strError == "")
                        {
                            var RoomList = TableToList.ToList<MeetingRoomMessage>(res.Item1);
                            var meetlis = TableToList.ToList<MeetingInfoMessage>(res.Item2);
                            meetlis.ForEach(i =>
                            {
                                //if (i.IsAppRove == 1)
                                //{
                                //    if (i.BeginTime > DateTime.Now)
                                //    {
                                //        i.State = 1;
                                //    }
                                //    else if (i.BeginTime < DateTime.Now && i.EndTime > DateTime.Now)
                                //    {
                                //        i.State = 2;
                                //    }

                                //}
                                //else
                                //{
                                //    if (i.BeginTime < DateTime.Now && i.EndTime > DateTime.Now && i.State == 2)
                                //    {
                                //        i.State = 2;
                                //    }

                                //}

                            });
                            RoomList.ForEach(j =>
                            {
                                if (j.ConferenceType == 2)
                                {
                                    j.strConferenceType = "视频会议室";
                                }
                                else
                                {
                                    j.strConferenceType = "普通会议室";
                                }

                            });
                            //list.MeetList = meetlis;
                            if (meetlis.Count > 0 && meetlis != null)
                            {
                                list.MeetList = list.MeetList.Union(meetlis).ToList<MeetingInfoMessage>();
                            }
                            if (RoomList.Count > 0 && RoomList != null)
                            {
                                list.RoomList = list.RoomList.Union(RoomList).ToList<MeetingRoomMessage>();
                            }
                            list.RecordCount = res.Item3;
                            list.PageCount = res.Item4;
                        }
                        else
                        {
                            LogEntity.OperateResult = "Fail";
                        }
                    }

                    list.MeetList = list.MeetList.DistinctBy(i => new { i.CInfoID, i.CRoomID }).ToList();
                    list.RoomList = list.RoomList.DistinctBy(i => i.CRoomID).ToList();
                }
                //var res = await dal.GetCRoomAndCInfo(query, out strError);


            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetMeetRoomAndInfo Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 获取会议室及相关会议信息（首页预约展示）（周日视图）
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetAndRoomInfoForWeek>> GetMeetRoomAndInfoForWeek(RoomQuery query)
        {
            PageList<MeetAndRoomInfoForWeek> pageList = new PageList<MeetAndRoomInfoForWeek>();
            List<MeetAndRoomInfoForWeek> roomlist = new List<MeetAndRoomInfoForWeek>();
            List<MeetingInfoForWeek> meetlist = new List<MeetingInfoForWeek>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetMeetRoomAndInfo";
            LogEntity.OperateObject = "GetMeetRoomAndInfo";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                query.BeginTime = Convert.ToDateTime(query.Date + " 00:00:01");
                var TimeEnd = Convert.ToDateTime(query.Date + " 23:59:59");
                query.EndTime = Convert.ToDateTime(query.Date + " 23:59:59").AddDays(6);
                if (query.RIDs.Count > 0 && query.RIDs != null)
                {
                    foreach (var item in query.RIDs)
                    {
                        query.RID = item;
                        var res = await dal.GetCRoomAndCInfo(query, out strError);

                        if (strError == "")
                        {
                            var roomlists = TableToList.ToList<MeetAndRoomInfoForWeek>(res.Item1);
                            var meetlists = TableToList.ToList<MeetingInfoForWeek>(res.Item2);
                            if (roomlists.Count > 0 && roomlists != null)
                            {
                                roomlist = roomlist.Union(roomlists).ToList<MeetAndRoomInfoForWeek>();
                            }
                            if (meetlists.Count > 0 && meetlists != null)
                            {
                                meetlist = meetlist.Union(meetlists).ToList<MeetingInfoForWeek>();
                            }
                            roomlist = roomlist.DistinctBy(i => i.CRoomID).ToList();
                            meetlist = meetlist.DistinctBy(i => new { i.CInfoID, i.CRoomID }).ToList();
                            roomlist.ForEach(l =>
                            {
                                List<MeetingInfoForWeek> listOne = new List<MeetingInfoForWeek>();
                                List<MeetingInfoForWeek> listTwo = new List<MeetingInfoForWeek>();
                                List<MeetingInfoForWeek> listThree = new List<MeetingInfoForWeek>();
                                List<MeetingInfoForWeek> listFour = new List<MeetingInfoForWeek>();
                                List<MeetingInfoForWeek> listFive = new List<MeetingInfoForWeek>();
                                List<MeetingInfoForWeek> listSix = new List<MeetingInfoForWeek>();
                                List<MeetingInfoForWeek> listSeven = new List<MeetingInfoForWeek>();
                                meetlist.ForEach(i =>
                                {
                                    i.Date = i.BeginTime.ToString("yyyy-MM-dd");
                                    i.Start = i.BeginTime.ToString("HH:mm");
                                    i.End = i.EndTime.ToString("HH:mm");
                                    //if (i.IsAppRove == 1)
                                    //{
                                    //    if (i.BeginTime > DateTime.Now)
                                    //    {
                                    //        i.State = 1;
                                    //    }
                                    //    else if (i.BeginTime < DateTime.Now && i.EndTime > DateTime.Now)
                                    //    {
                                    //        i.State = 2;
                                    //    }

                                    //}
                                    //else
                                    //{
                                    //    if (i.BeginTime < DateTime.Now && i.EndTime > DateTime.Now && i.State == 2)
                                    //    {
                                    //        i.State = 2;
                                    //    }

                                    //}

                                    if (l.CRoomID == i.CRoomID)
                                    {

                                        if (i.BeginTime >= query.BeginTime && i.EndTime <= TimeEnd)
                                        {
                                            listOne.Add(i);
                                        }
                                        else if (i.BeginTime >= query.BeginTime.AddDays(1) && i.EndTime <= TimeEnd.AddDays(1))
                                        {
                                            listTwo.Add(i);
                                        }
                                        else if (i.BeginTime >= query.BeginTime.AddDays(2) && i.EndTime <= TimeEnd.AddDays(2))
                                        {
                                            listThree.Add(i);
                                        }
                                        else if (i.BeginTime >= query.BeginTime.AddDays(3) && i.EndTime <= TimeEnd.AddDays(3))
                                        {
                                            listFour.Add(i);
                                        }
                                        else if (i.BeginTime >= query.BeginTime.AddDays(4) && i.EndTime <= TimeEnd.AddDays(4))
                                        {
                                            listFive.Add(i);
                                        }
                                        else if (i.BeginTime >= query.BeginTime.AddDays(5) && i.EndTime <= TimeEnd.AddDays(5))
                                        {
                                            listSix.Add(i);
                                        }
                                        else if (i.BeginTime >= query.BeginTime.AddDays(6) && i.EndTime <= TimeEnd.AddDays(6))
                                        {
                                            listSeven.Add(i);
                                        }

                                    }
                                    l.listOne = listOne;
                                    l.listTwo = listTwo;
                                    l.listThree = listThree;
                                    l.listFour = listFour;
                                    l.listFive = listFive;
                                    l.listSix = listSix;
                                    l.listSeven = listSeven;



                                });

                            });
                            pageList.List = roomlist;
                            pageList.RecordCount = res.Item3;
                            pageList.PageCount = res.Item4;
                        }
                        else
                        {
                            LogEntity.OperateResult = "Fail";
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetMeetRoomAndInfo Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return pageList;
        }

        /// <summary>
        /// 获取会议室及相关会议信息（首页预约展示）移动端
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageListMobile<MeetAndRoomInfoForMobile>> GetMeetRoomAndInfoForMobile(RoomQuery query)
        {
            PageListMobile<MeetAndRoomInfoForMobile> list = new PageListMobile<MeetAndRoomInfoForMobile>();
            List<MeetAndRoomInfoForMobile> meetAndRoomInfoForMobile = new List<MeetAndRoomInfoForMobile>();
            List<MeetingInfoMessage> meetingInfoMessage = new List<MeetingInfoMessage>();
            SubscribeInfo subscribeInfo = new SubscribeInfo();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetMeetRoomAndInfoForMobile";
            LogEntity.OperateObject = "GetMeetRoomAndInfoForMobile";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                var res = await dal.GetMeetRoomAndInfoForMobile(query, out strError);
                var time = await setdal.GetSubscribe(out strError);
                if (strError == "")
                {
                    meetAndRoomInfoForMobile = TableToList.ToList<MeetAndRoomInfoForMobile>(res.Item1);
                    meetingInfoMessage = TableToList.ToList<MeetingInfoMessage>(res.Item2);
                    //meetingInfoMessage.ForEach(i =>
                    //{
                    //    //if (i.IsAppRove == 1)
                    //    //{
                    //    //    if (i.BeginTime > DateTime.Now)
                    //    //    {
                    //    //        i.State = 1;
                    //    //    }
                    //    //    else if (i.BeginTime < DateTime.Now && i.EndTime > DateTime.Now && i.State == 2)
                    //    //    {
                    //    //        i.State = 2;
                    //    //    }

                    //    //}
                    //    //else
                    //    //{
                    //    //    if (i.BeginTime < DateTime.Now && i.EndTime > DateTime.Now && i.State == 2)
                    //    //    {
                    //    //        i.State = 2;
                    //    //    }

                    //    //}

                    //});
                    var subscribe = TableToList.ToList<SubscribeInfo>(time);
                    subscribeInfo = subscribe[0];

                    foreach (var item in meetAndRoomInfoForMobile)
                    {
                        item.date = subscribeInfo.SubscribeBegin + "-" + subscribeInfo.SubscribeEnd;
                    }
                    foreach (var item in meetingInfoMessage)
                    {
                        item.Date = item.BeginTime.ToString("yyyy-MM-dd");
                        item.Start = item.BeginTime.ToString("HH:mm");
                        item.End = item.EndTime.ToString("HH:mm");
                    }

                    foreach (var a in meetAndRoomInfoForMobile)
                    {
                        List<MeetingInfoMessage> meetingInfoList = new List<MeetingInfoMessage>();
                        foreach (var b in meetingInfoMessage)
                        {
                            if (a.CRoomID == b.CRoomID)
                            {
                                b.CRoomName = a.ConferenceName;
                                meetingInfoList.Add(b);
                            }
                        }
                        a.meetingInfoList = meetingInfoList;
                    }

                    list.List = meetAndRoomInfoForMobile;
                    list.RecordCount = res.Item3;
                    list.PageCount = res.Item4;
                    list.IsHaveNext = res.Item5;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetMeetRoomAndInfoForMobile Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 获取会议室及相关会议信息（首页预约展示）Pad
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MeetAndRoomInfoForPad> GetMeetRoomAndInfoForPad(CRoomPadQuery query)
        {
            MeetAndRoomInfoForPad room = new MeetAndRoomInfoForPad();
            List<MeetAndRoomInfoForPad> meetAndRoomInfoForPad = new List<MeetAndRoomInfoForPad>();
            List<MeetingInfoForPad> meetingInfoMessage = new List<MeetingInfoForPad>();

            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetMeetRoomAndInfoForMobile";
            LogEntity.OperateObject = "GetMeetRoomAndInfoForMobile";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CRoomPadQuery>(query);
            try
            {
                var res = await dal.GetMeetRoomAndInfoForPad(query, out strError);

                if (strError == "")
                {
                    meetAndRoomInfoForPad = TableToList.ToList<MeetAndRoomInfoForPad>(res.Item1);
                    meetingInfoMessage = TableToList.ToList<MeetingInfoForPad>(res.Item2);
                    var list = TableToList.ToList<StateColorEntity>(res.Item3);
                    if (meetingInfoMessage.Count > 0 && meetingInfoMessage != null)
                    {
                        foreach (var item in meetingInfoMessage)
                        {
                            item.Start = item.BeginTime.ToString("HH:mm");
                            item.End = item.EndTime.ToString("HH:mm");
                        }
                    }
                    room = meetAndRoomInfoForPad[0];
                    if (meetingInfoMessage.Count > 0 && meetingInfoMessage != null)
                    {
                        if (meetingInfoMessage[0].BeginTime.AddMinutes(-PadNotice) <= DateTime.Now)
                        {
                            room.CInfoID = meetingInfoMessage[0].CInfoID;
                            room.ConferenceTheme = meetingInfoMessage[0].ConferenceTheme;
                            room.MeetTime = meetingInfoMessage[0].Start + "-" + meetingInfoMessage[0].End;
                            var StateText = "";
                            var IsSignInText = "";

                            if (meetingInfoMessage[0].State == 1)
                            {
                                room.RoomState = 2;
                                room.PadLightCode = list.Where(i => i.LightStateId == 2).FirstOrDefault().ColorCode;
                                StateText = "未开始";
                            }
                            else if (meetingInfoMessage[0].State == 2)
                            {
                                room.RoomState = 3;
                                room.PadLightCode = list.Where(i => i.LightStateId == 3).FirstOrDefault().ColorCode;
                                StateText = "进行中";
                            }
                            else
                            {
                                room.RoomState = 2;
                                room.PadLightCode = list.Where(i => i.LightStateId == 2).FirstOrDefault().ColorCode;
                                StateText = "未开始";
                            }
                            if (meetingInfoMessage[0].IsSignIn == 1)
                            {
                                IsSignInText = "已签到";
                            }
                            else if (meetingInfoMessage[0].IsSignIn == 0)
                            {
                                IsSignInText = "未签到";
                            }
                            else if (meetingInfoMessage[0].IsSignIn == 2)
                            {
                                IsSignInText = "无需签到";
                            }
                            if (meetingInfoMessage[0].EndTime < DateTime.Now)
                            {
                                IsSignInText = "已延时";
                            }

                            room.StateAndIsSignIn = StateText + "(" + IsSignInText + ")";
                            room.Coordinator = meetingInfoMessage[0].Coordinator;
                            room.meetingInfoList = meetingInfoMessage.OrderBy(u => u.BeginTime).Skip(1).Take(meetingInfoMessage.Count).ToList();




                        }
                        else
                        {
                            room.RoomState = 1;
                            room.PadLightCode = list.Where(i => i.LightStateId == 1).FirstOrDefault().ColorCode;
                            room.StateAndIsSignIn = "空闲中";
                            room.meetingInfoList = meetingInfoMessage;
                        }
                    }
                    else
                    {
                        room.RoomState = 1;
                        room.PadLightCode = list.Where(i => i.LightStateId == 1).FirstOrDefault().ColorCode;
                        room.StateAndIsSignIn = "空闲中";
                        room.meetingInfoList = meetingInfoMessage;

                    }


                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetMeetRoomAndInfoForMobile Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return room;
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingRoomInfo>> GetCRoomByRID(RoomQuery query)
        {
            PageList<MeetingRoomInfo> list = new PageList<MeetingRoomInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCRoomByRID";
            LogEntity.OperateObject = "GetCRoomByRID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                var res = await dal.GetCRoomByRID(query, out strError);

                if (strError == "")
                {
                    //  list.List = TableToList.ToList<MeetingRoomInfo>(res.Item1);
                    list.List = TableToList.ToList<MeetingRoomInfo>(res.Item1);
                    list.List.ForEach(i =>
                    {
                        if (i.ConferenceType == 2)
                        {
                            i.strConferenceType = "视频会议室";
                        }
                        else
                        {
                            i.strConferenceType = "普通会议室";
                        }
                    });
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCRoomByRID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据区域ID集合获取当前区域下所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingRoomInfo>> GetCRoomByRIDs(RoomQuery query)
        {
            PageList<MeetingRoomInfo> list = new PageList<MeetingRoomInfo>();
            List<MeetingRoomInfo> roomlist = new List<MeetingRoomInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCRoomByRIDs";
            LogEntity.OperateObject = "GetCRoomByRIDs";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                if (query.RIDs.Count > 0 && query.RIDs != null)
                {
                    foreach (var item in query.RIDs)
                    {
                        query.RID = item;
                        var res = await dal.GetCRoomByRID(query, out strError);

                        if (strError == "")
                        {
                            roomlist = TableToList.ToList<MeetingRoomInfo>(res.Item1);
                            if (roomlist.Count > 0 && roomlist != null)
                            {
                                list.List = list.List.Union(roomlist).ToList<MeetingRoomInfo>();
                            }
                            list.RecordCount = res.Item2;
                            list.PageCount = res.Item3;
                        }
                        else
                        {
                            LogEntity.OperateResult = "Fail";
                        }
                    }
                    list.List = list.List.DistinctBy(I => I.ID).ToList();
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCRoomByRIDs Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingRoomInfo>> GetCRoomInfoListByRID(RoomQuery query)
        {
            PageList<MeetingRoomInfo> list = new PageList<MeetingRoomInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCRoomInfoListByRID";
            LogEntity.OperateObject = "GetCRoomInfoListByRID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                var res = await dal.GetCRoomInfoListByRID(query, out strError);

                if (strError == "")
                {
                    list.List = TableToList.ToList<MeetingRoomInfo>(res.Item1);
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCRoomInfoListByRID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        public async Task<List<PadColorEntity>> GetAllColor(int padType)
        {
            var list = new List<PadColorEntity>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetAllColor";
            LogEntity.OperateObject = "GetAllColor";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "padtype:" + padType;
            try
            {
                var res = await dal.GetAllColor(padType, out strError);

                if (strError == "")
                {
                    list = TableToList.ToList<PadColorEntity>(res);

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetAllColor Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        public async Task<List<StateColorEntity>> GetStateColorByPadType(int padType)
        {
            var list = new List<StateColorEntity>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetStateColorByPadType";
            LogEntity.OperateObject = "GetStateColorByPadType";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "padtype:" + padType;
            try
            {
                var res = await dal.GetStateColorByPadType(padType, out strError);

                if (strError == "")
                {
                    list = TableToList.ToList<StateColorEntity>(res);

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetStateColorByPadType Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室信息（预约编辑回显数据）
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingRoomInfo>> GetCRoomByRIDForUpdate(RoomQuery query)
        {
            PageList<MeetingRoomInfo> list = new PageList<MeetingRoomInfo>();
            List<MeetingRoomInfo> meetingRoomInfolist = new List<MeetingRoomInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCRoomByRID";
            LogEntity.OperateObject = "GetCRoomByRID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                var res = await dal.GetCRoomByRID(query, out strError);

                if (strError == "")
                {
                    meetingRoomInfolist = TableToList.ToList<MeetingRoomInfo>(res.Item1);
                    string[] CRoomIDs = query.CRoomIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < CRoomIDs.Length; i++)
                    {
                        foreach (var item in meetingRoomInfolist)
                        {

                            if (CRoomIDs[i] == item.ID.ToString())
                            {
                                item.IsChoice = true;
                            }
                        }
                    }
                    meetingRoomInfolist.ForEach(i =>
                    {
                        if (i.ConferenceType == 2)
                        {
                            i.strConferenceType = "视频会议室";
                        }
                        else
                        {
                            i.strConferenceType = "普通会议室";
                        }
                    });
                    list.List = meetingRoomInfolist;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCRoomByRID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据查询关键字获取所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingRoomInfo>> GetCRoomByKey(RoomQuery query)
        {
            PageList<MeetingRoomInfo> list = new PageList<MeetingRoomInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCRoomByKey";
            LogEntity.OperateObject = "GetCRoomByKey";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<RoomQuery>(query);
            try
            {
                var res = await dal.GetCRoomByKey(query, out strError);

                if (strError == "")
                {
                    list.List = TableToList.ToList<MeetingRoomInfo>(res.Item1);
                    list.List.ForEach(i =>
                    {
                        if (i.ConferenceType == 2)
                        {
                            i.strConferenceType = "视频会议室";
                        }
                        else
                        {
                            i.strConferenceType = "普通会议室";
                        }
                    });
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                    list.IsHaveNext = res.Item4;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCRoomByKey Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 管理员查看会议信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingInfo>> GetCInfoByAdmin(CInfoQuery query)
        {
            PageList<MeetingInfo> list = new PageList<MeetingInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCInfoByAdmin";
            LogEntity.OperateObject = "GetCInfoByAdmin";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var res = await dal.GetCInfoByAdmin(query, out strError);

                if (strError == "")
                {
                    list.List = TableToList.ToList<MeetingInfo>(res.Item1);
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCInfoByAdmin Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 当前登陆人员查看会议信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingInfo>> GetCInfoByUser(CInfoQuery query)
        {
            PageList<MeetingInfo> list = new PageList<MeetingInfo>();
            List<MeetingInfo> list1 = new List<MeetingInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCInfoByUser";
            LogEntity.OperateObject = "GetCInfoByUser";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var length = "";
                var setRes = setdal.GetSettingSystem(out strError).Result;
                var set = TableToList.ToList<SettingSystem>(setRes)[0];
                for (int i = 0; i < set.CNumberLength; i++)
                {
                    length += "0";
                }
                var res = await dal.GetCInfoByUser(query, out strError);
                var regional = await setting.GetRegionalForMobile(new RegionalQuery()
                {
                    Key = "",
                    pageIndex = 1,
                    pageSize = 10000,
                });
                var regionalList = regional.List;
                if (strError == "")
                {

                    list1 = TableToList.ToList<MeetingInfo>(res.Item1);
                    list1.ForEach(i =>
                    {
                        i.MeetingNumber = set.CNumberPrefix + i.ID.ToString(length);
                        foreach (var item in regionalList)
                        {
                            if (i.RegionalID == item.ID)
                            {
                                i.RegionalName = item.RegionalName;
                            }
                        }
                        //if (i.IsAppRove == 1)
                        //{
                        if (i.MeetState == 1)
                        {
                            i.State = "已预订";
                        }
                        else if (i.MeetState == 2)
                        {
                            i.State = "会议中";
                        }
                        else if (i.MeetState == 3)
                        {
                            i.State = "已结束";
                        }
                        else if (i.MeetState == 4)
                        {
                            i.State = "审批中";
                        }
                        else if (i.MeetState == 5)
                        {
                            i.State = "已取消";
                        }
                        else if (i.MeetState == 6)
                        {
                            i.State = "已作废";
                        }
                        else if (i.MeetState == 7)
                        {
                            i.State = "审批未通过";

                        }

                        //}
                        //        else
                        //        {
                        //            if (i.BeginTime <= DateTime.Now && i.EndTime >= DateTime.Now && i.MeetState == 2)
                        //            {
                        //                i.State = "会议中"; ;
                        //            }
                        //            else if (i.BeginTime > DateTime.Now && i.MeetState == 1)
                        //            {
                        //                i.State = "已预订";
                        //            }
                        //            else if (i.MeetState == 3)
                        //            {
                        //                i.State = "已结束";
                        //            }
                        //            else if (i.MeetState == 4)
                        //            {
                        //                i.State = "审批中";
                        //            }


                        //        }

                        i.date = Convert.ToDateTime(i.BeginTime).ToString("yyyy-MM-dd");
                        i.Start = Convert.ToDateTime(i.BeginTime).ToString("HH:mm");
                        i.End = Convert.ToDateTime(i.EndTime).ToString("HH:mm");
                    });
                    list.List = list1;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                    list.IsHaveNext = res.Item4;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCInfoByUser Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据会议ID获取会议信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MeetingInfoSingle> GetCInfoByID(CInfoQuery query)
        {
            string strError = "";

            MeetingInfoSingle meetingInfoSingle = new MeetingInfoSingle();
            List<MeetingInfoSingle> list = new List<MeetingInfoSingle>();

            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCInfoByID";
            LogEntity.OperateObject = "GetCInfoByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var time = setdal.GetSubscribe(out strError).Result;
                var subscribe = TableToList.ToList<SubscribeInfo>(time)[0];

                var res = await dal.GetCInfoByID(query, out strError);

                if (strError == "")
                {
                    List<MeetingRoomType> typeList = new List<MeetingRoomType>();

                    list = TableToList.ToList<MeetingInfoSingle>(res.Item1);
                    var roomlist = TableToList.ToList<MeetingRoomType>(res.Item2);
                    meetingInfoSingle = list[0];

                    roomlist.ForEach(i =>
                     {
                         MeetingRoomType type = new MeetingRoomType();
                         type.CRoomID = i.CRoomID;
                         type.CRoomName = i.CRoomName;
                         type.CRoomType = i.CRoomType;
                         typeList.Add(type);
                     });

                    meetingInfoSingle.CRoomTypes = typeList;
                    meetingInfoSingle.CRoomTypes.ForEach(i =>
                    {
                        if (i.CRoomType == 2)
                        {
                            i.strCRoomType = "视频会议室";
                        }
                        else
                        {
                            i.strCRoomType = "普通会议室";
                        }
                    });
                    meetingInfoSingle.date = Convert.ToDateTime(meetingInfoSingle.BeginTime).ToString("yyyy-MM-dd");
                    meetingInfoSingle.Begin = Convert.ToDateTime(meetingInfoSingle.BeginTime).ToString("HH:mm");
                    meetingInfoSingle.End = Convert.ToDateTime(meetingInfoSingle.EndTime).ToString("HH:mm");
                    meetingInfoSingle.CRooms = meetingInfoSingle.CRoom + "/" + meetingInfoSingle.CRooms;
                    meetingInfoSingle.CRooms = meetingInfoSingle.CRooms.Substring(0, meetingInfoSingle.CRooms.Length - 1);
                    meetingInfoSingle.CRoomIDs = meetingInfoSingle.CRoomID + "," + meetingInfoSingle.CRoomIDs;
                    meetingInfoSingle.subscribeBegin = subscribe.SubscribeBegin;
                    meetingInfoSingle.subscribeEnd = subscribe.SubscribeEnd;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetCInfoByID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return meetingInfoSingle;
        }
        public async Task<DataTable> GetCInfoByID(int InfoId)
        {
            var res = await dal.GetCInfoByID(InfoId);
            return res;
        }
        public DataSet getMeetInfoAndUserPhone(int iD, out string StrError)
        {
            var res = dal.getMeetInfoAndUserPhone(iD, out StrError);
            return res;
        }
        public DataSet GetMeeetUserPhoneFromOrgcalendars(int iD, out string StrError)
        {
            var res = dal.GetMeeetUserPhoneFromOrgcalendars(iD, out StrError);
            return res;
        }
        public Task<bool> updateWxState(int CinfoId, out string strError)
        {
            var res = dal.updateWxState(CinfoId, out strError);
            return res;
        }
        public bool IsSendWX(int CinfoId, out string strError)
        {
            var res = dal.IsSendWX(CinfoId, out strError);
            return res;
        }
        public Task<bool> MeetUpdateEnd(int CinfoId)
        {
            var res = dal.MeetUpdateEnd(CinfoId, out string strError);
            return res;
        }
        public Task<bool> PadColorUpdate(StateColorQuery P)
        {
            var res = dal.PadColorUpdate(P, out string strError);
            return res;
        }
        /// <summary>
        /// 根据会议ID修改会议信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> UpdateMeetingInfoByID(MeetingOrder entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateMeetingInfoByID";
            LogEntity.OperateObject = "UpdateMeetingInfoByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {
                bResult = await dal.UpdateMeetingInfoByID(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateMeetingInfoByID Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        ///  当前登录用户查看参与会议列表（创建，协调，主持，纪要，内部参会）   所有会议
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingInfo>> GetAllCInfoByUser(CInfoQuery query)
        {
            //TODO
            PageList<MeetingInfo> list = new PageList<MeetingInfo>();
            List<MeetingInfo> list1 = new List<MeetingInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetAllCInfoByUser";
            LogEntity.OperateObject = "GetAllCInfoByUser";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var length = "";
                var setRes = setdal.GetSettingSystem(out strError).Result;
                var set = TableToList.ToList<SettingSystem>(setRes)[0];
                for (int i = 0; i < set.CNumberLength; i++)
                {
                    length += "0";
                }
                var res = await dal.GetAllCInfoByUser(query, out strError);
                list1 = TableToList.ToList<MeetingInfo>(res.Item1);
                var regional = setting.GetRegionalForMobile(new RegionalQuery()
                {
                    Key = "",
                    pageIndex = 1,
                    pageSize = 10000,
                });
                var regionalList = regional.Result.List;
                if (strError == "")
                {
                    list1.ForEach(i =>
                    {
                        i.MeetingNumber = set.CNumberPrefix + i.ID.ToString(length);
                        foreach (var item in regionalList)
                        {
                            if (i.RegionalID == item.ID)
                            {
                                i.RegionalName = item.RegionalName;
                            }
                        }
                        if (i.MeetState == 1)
                        {
                            i.State = "已预订";
                        }
                        else if (i.MeetState == 2)
                        {
                            i.State = "会议中";
                        }
                        else if (i.MeetState == 3)
                        {
                            i.State = "已结束";
                        }
                        else if (i.MeetState == 4)
                        {
                            i.State = "审批中";
                        }
                        else if (i.MeetState == 5)
                        {
                            i.State = "已取消";
                        }
                        else if (i.MeetState == 6)
                        {
                            i.State = "已作废";
                        }
                        else if (i.MeetState == 7)
                        {
                            i.State = "未通过";

                        }
                        else if (i.MeetState == 8)
                        {
                            i.State = "待发起";
                        }

                        i.date = Convert.ToDateTime(i.BeginTime).ToString("yyyy-MM-dd");
                        i.Start = Convert.ToDateTime(i.BeginTime).ToString("HH:mm");
                        i.End = Convert.ToDateTime(i.EndTime).ToString("HH:mm");
                    });
                    list.List = list1;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                    list.IsHaveNext = res.Item4;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetAllCInfoByUser Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 会议转赠
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> TransferMeeting(TransferMeeting entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.TransferMeeting";
            LogEntity.OperateObject = "TransferMeeting";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<TransferMeeting>(entity);
            try
            {
                if (entity.Transfer > 0)
                {
                    bResult = await dal.TransferMeeting(entity, out strError);
                    if (!bResult)
                    {
                        LogEntity.OperateResult = "Fail";
                        bResult = false;
                    }
                }
                else
                {
                    strError = "请选择被转赠人";
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }

            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("TransferMeeting Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        /// 会议延长
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> ExtendMeeting(ExtendMeeting entity)
        {
            string strError = "";

            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.ExtendMeeting";
            LogEntity.OperateObject = "ExtendMeeting";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<ExtendMeeting>(entity);
            try
            {
                //会议延长是否有时间冲突
                var list = await GetRoomInfoByTime(new CRoomTimeQuery()
                {
                    CInfoID = entity.ID,
                    CRoomIDs = entity.CRoomID + "," + entity.CRoomIDs,
                    BeginTime = entity.BeginTime,
                    EndTime = entity.EndTime.AddMinutes(entity.Extend),

                });
                if (list != null && list.Count > 0)
                {
                    bResult = false;
                    foreach (var item in list)
                    {
                        strError += item.ConferenceName + "时间冲突，";
                    }
                    return (bResult, strError);
                }

                bResult = await dal.ExtendMeeting(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("ExtendMeeting Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 删除（取消）会议信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> DeleteMeetingInfo(TransferMeeting entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.DeleteMeetingInfo";
            LogEntity.OperateObject = "TransferMeeting";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<TransferMeeting>(entity);
            try
            {
                if (ExchangeOn == 1)
                {


                    var address = exchangeToDbDal.GetUserEmail(entity.UserID);


                    EmailEntity ap = new EmailEntity();
                    var meetList = exchangeToDbDal.GetMeetExchangeItemIdByID(entity.ID);
                    foreach (var meet in meetList)
                    {
                        ExChangeHelper helper = new ExChangeHelper(5, meet.ewsAccount, meet.ewsPwd, meet.ewsUrl);
                        ap.Start = meet.BeginTime;
                        ap.End = meet.EndTime;
                        ap.ID = meet.ExchangeItemId;

                        if (meet.IsAuto)
                        {
                            bResult = helper.CannelMeeting(ap, meet.OrderUser, out strError);
                        }
                        else
                        {

                            bResult = helper.CannelMeeting(ap, address.Mail, out strError);
                        }

                    }





                    if (bResult)
                    {
                        bResult = await dal.DeleteMeetingInfo(entity, out strError);
                    }
                    else
                    {
                        LogEntity.OperateResult = "Fail";
                        bResult = false;
                    }
                }
                else {
                    bResult = await dal.DeleteMeetingInfo(entity, out strError);
                    if (!bResult)
                    {
                        LogEntity.OperateResult = "Fail";
                        bResult = false;
                    }
              //      CMSHttpHelper HTTP = new CMSHttpHelper();
                //    HTTP.ResetPasscode(entity.ID);
                }
            
            
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("DeleteMeetingInfo Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        /// 提前结束会议信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> UpdateMeetingEnd(CInfoQuery entity)
        {
            string strError = "";
            bool bResult = true;
            entity.EndTime = DateTime.Now;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateMeetingEnd";
            LogEntity.OperateObject = "UpdateMeetingEnd";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(entity);
            try
            {
                if (ExchangeOn == 1)
                {
                    var address = exchangeToDbDal.GetUserEmail(entity.UserID);

                    EmailEntity ap = new EmailEntity();
                    var meetList = exchangeToDbDal.GetMeetExchangeItemIdByID(entity.CInfoID);
                    foreach (var meet in meetList)
                    {
                        ExChangeHelper helper = new ExChangeHelper(5, meet.ewsAccount, meet.ewsPwd, meet.ewsUrl);
                        ap.OldStart = meet.BeginTime;
                        ap.OldEnd = meet.EndTime;
                        ap.ID = meet.ExchangeItemId;

                        if (meet.IsAuto)
                        {
                            bResult = helper.CannelMeeting(ap, meet.OrderUser, out strError);
                        }
                        else
                        {

                            bResult = helper.CannelMeeting(ap, address.Mail, out strError);
                        }

                    }

                    if (bResult)
                    {
                        bResult = await dal.UpdateMeetingEnd(entity, out strError);
                    }
                    else
                    {
                        LogEntity.OperateResult = "Fail";
                        bResult = false;
                    }
                }
                else
                {
                    bResult = await dal.UpdateMeetingEnd(entity, out strError);
                    if (!bResult)
                    {
                        LogEntity.OperateResult = "Fail";
                        bResult = false;
                    }
                }

                //   CMSHttpHelper HTTP = new CMSHttpHelper();
                //HTTP.ResetPasscode(entity.CInfoID);
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateMeetingEnd Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        /// 添加会议设备
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> AddMeetingEquipment(MeetingEquipment entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.AddMeetingEquipment";
            LogEntity.OperateObject = "AddMeetingEquipment";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingEquipment>(entity);
            try
            {
                var list = await GetMeetingEquipment(new EquipmentQuery()
                {
                    Key = "",
                });
                foreach (var item in list.List)
                {
                    if (item.EquipmentName.Trim() == entity.EquipmentName.Trim())
                    {
                        bResult = false;
                        strError = "已存在同名的会议设备";
                        return (bResult, strError);
                    }
                }

                bResult = await dal.AddMeetingEquipment(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("AddMeetingEquipment Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 删除会议设备
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> DeleteMeetingEquipment(MeetingEquipment entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.DeleteMeetingEquipment";
            LogEntity.OperateObject = "DeleteMeetingEquipment";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingEquipment>(entity);
            try
            {
                bResult = await dal.DeleteMeetingEquipment(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("DeleteMeetingEquipment Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        /// 根据ID修改会议设备名称
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateMeetingEquipment(MeetingEquipment entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateMeetingEquipment";
            LogEntity.OperateObject = "UpdateMeetingEquipment";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingEquipment>(entity);
            try
            {
                var list = await GetMeetingEquipment(new EquipmentQuery()
                {
                    Key = "",
                });
                foreach (var item in list.List)
                {
                    if (item.EquipmentName.Trim() == entity.EquipmentName.Trim())
                    {
                        bResult = false;
                        strError = "已存在同名的会议设备";
                        return (bResult, strError);
                    }
                }

                bResult = await dal.UpdateMeetingEquipment(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateMeetingEquipment Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 根据查询关键字获取所有会议设备信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingEquipment>> GetMeetingEquipment(EquipmentQuery query)
        {
            PageList<MeetingEquipment> list = new PageList<MeetingEquipment>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetMeetingEquipment";
            LogEntity.OperateObject = "GetMeetingEquipment";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<EquipmentQuery>(query);
            try
            {
                var res = await dal.GetMeetingEquipment(query, out strError);

                if (strError == "")
                {
                    list.List = TableToList.ToList<MeetingEquipment>(res.Item1);
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetMeetingEquipment Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据会议ID和时间查看是否有预约会议室时间冲突
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<List<CRoomName>> GetRoomInfoByTime(CRoomTimeQuery query)
        {

            List<CRoomName> list1 = new List<CRoomName>();
            List<CRoomName> list2 = new List<CRoomName>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetRoomInfoByTime";
            LogEntity.OperateObject = "GetRoomInfoByTime";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CRoomTimeQuery>(query);
            try
            {
                var res = await dal.GetRoomInfoByTime(query, out strError);

                if (strError == "")
                {
                    list1 = TableToList.ToList<CRoomName>(res.Item1);
                    list2 = TableToList.ToList<CRoomName>(res.Item2);
                    foreach (var item in list1)
                    {
                        list2.Add(item);
                    }
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetRoomInfoByTime Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list2;
        }

        /// <summary>
        /// 会议审批
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> ApprovalMeeting(ApprovalMeeting entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.ApprovalMeeting";
            LogEntity.OperateObject = "ApprovalMeeting";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<ApprovalMeeting>(entity);
            try
            {
                bResult = await dal.ApprovalMeeting(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("ApprovalMeeting Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return bResult;
        }

        /// <summary>
        /// 根据用户ID查看是否有会议纪要48小时内没有上传
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<List<CheckMinutesEntity>> CheckMinutes(CheckMinutesQuery query)
        {

            List<CheckMinutesEntity> list = new List<CheckMinutesEntity>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.CheckMinutes";
            LogEntity.OperateObject = "CheckMinutes";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CheckMinutesQuery>(query);
            try
            {
                var res = await dal.CheckMinutes(query, out strError);

                if (strError == "")
                {
                    list = TableToList.ToList<CheckMinutesEntity>(res);
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("CheckMinutes Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        /// <summary>
        /// 根据用户ID查看是否有会议纪要48小时内没有上传(登陆提示)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<string> CheckMinutesNotice(CheckMinutesQuery query)
        {


            string strError = "";
            string Notice = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.CheckMinutesNotice";
            LogEntity.OperateObject = "CheckMinutesNotice";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CheckMinutesQuery>(query);
            try
            {
                var res = await dal.CheckMinutes(query, out strError);

                if (strError == "")
                {
                    var list = TableToList.ToList<CheckMinutesEntity>(res);
                    if (list != null && list.Count > 0)
                    {

                        foreach (var item in list)
                        {
                            Notice += "会议名称为：" + item.ConferenceTheme + ",";

                            await dal.MinutesPointsDeducted(new CheckMinutesEntity()//扣除积分（10）
                            {
                                ID = item.ID,

                            }, out strError);
                        }
                        Notice += "的会议纪要在48小时内没有上传";

                    }

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("CheckMinutesNotice Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return Notice;
        }

        /// <summary>
        /// 系统日志
        /// </summary>
        private void RecordLog()
        {
            LogEntity.Operator = Operator;
            LogEntity.OperateIP = OperaIP;
            ULogWork.CLogToDataBase.RecordOperateLog(LogEntity);
        }

        /// <summary>
        /// 签到
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="cinfoId"></param>
        /// <returns></returns>
        public async Task<(bool, int)> SignInCInfo(string mobile, string cinfoId)
        {

            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.SignInCInfo";
            LogEntity.OperateObject = "SignInCInfo";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = mobile + "_" + cinfoId;
            try
            {
                var (res, isSign, error) = await dal.SignInCInfo(mobile, cinfoId);

                if (error == "")
                {
                    return (res, isSign);
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("CheckMinutes Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (false, 0);
        }

        /// <summary>
        /// 获取会议须知
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<ConferenceNotice> GetConferenceNotice()
        {
            ConferenceNotice conferenceNotice = new ConferenceNotice();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetConferenceNotice";
            LogEntity.OperateObject = "GetConferenceNotice";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {
                var res = await dal.GetConferenceNotice(out strError);

                if (strError == "")
                {
                    conferenceNotice = TableToList.ToList<ConferenceNotice>(res)[0];

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetConferenceNotice Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return conferenceNotice;
        }

        /// <summary>
        /// 根据ID修改会议须知
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string)> UpdateConferenceNotice(ConferenceNotice entity)
        {
            string strError = "";
            bool bResult = true;
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateConferenceNotice";
            LogEntity.OperateObject = "UpdateConferenceNotice";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<ConferenceNotice>(entity);
            try
            {

                bResult = await dal.UpdateConferenceNotice(entity, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    bResult = false;
                }
            }
            catch (Exception ex)
            {
                bResult = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateConferenceNotice Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (bResult, strError);
        }

        /// <summary>
        /// 根据查询关键字获取会议转赠信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<TransferRecord>> GetTransferRecord(TransferMeeting query)
        {
            PageList<TransferRecord> list = new PageList<TransferRecord>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetTransferRecord";
            LogEntity.OperateObject = "GetTransferRecord";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<TransferMeeting>(query);
            try
            {
                var length = "";
                var setRes = setdal.GetSettingSystem(out strError).Result;
                var set = TableToList.ToList<SettingSystem>(setRes)[0];
                for (int i = 0; i < set.CNumberLength; i++)
                {
                    length += "0";
                }
                var res = await dal.GetTransferRecord(query, out strError);

                if (strError == "")
                {
                    list.List = TableToList.ToList<TransferRecord>(res.Item1);
                    list.List.ForEach(i =>
                    {
                        i.MeetingNumber = set.CNumberPrefix + i.CInfoID.ToString(length);
                        i.DateTime = Convert.ToDateTime(i.BeginTime).ToString("yyyy-MM-dd");
                        // i.date = Convert.ToDateTime(i.BeginTime).ToString("yyyy-MM-dd");
                        i.start = i.BeginTime.ToString("HH:mm");
                        i.end = i.EndTime.ToString("HH:mm");
                        i.WhenCreated = i.WCreated.ToString("G");
                    });
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetTransferRecord Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        public CInfoIds getMeetIdBystrBOID(string strBOTID)
        {
            var res = setdal.getMeetIdBystrBOID(strBOTID, out string strError).Result;
            if (strError == "")
            {
                CInfoIds info = TableToList.ToList<CInfoIds>(res).FirstOrDefault();
                return info;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        ///  根据组织ID查询组织日历信息    
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<List<CalendarsMeetInfo>> GetOrgCalendars(CalendarsMeetQuery query)
        {
            List<CalendarsMeetInfo> list = new List<CalendarsMeetInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetOrgCalendars";
            LogEntity.OperateObject = "GetOrgCalendars";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CalendarsMeetQuery>(query);
            try
            {

                var dt = await dal.GetOrgCalendars(query, out strError);
                if (strError == "")
                {
                    list = TableToList.ToList<CalendarsMeetInfo>(dt);
                    list.ForEach(i =>
                    {

                        if (i.State == 1)
                        {
                            i.Color = "#33cd9b";
                        }
                        //if (i.BeginTime < DateTime.Now && i.EndTime > DateTime.Now && i.State == 2)
                        //{
                        //    i.State = 2;
                        //    i.Color = "#f97e6e";
                        //}
                        //if (i.State == 3)
                        //{
                        //    i.Color = "#c7c7c7";
                        //}
                        if (i.State == 2)
                        {
                            i.Color = "#ffc302";
                        }


                    });
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetOrgCalendars Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }

        public Task<DataTable> GetCInfoPwdByID(int cinfoId)
        {
            var res = dal.GetCInfoPwdByID(cinfoId);
            return res;
        }

        public async Task<List<MeetRoomPwd>> GetCRoomPwd(CInfoPwdQuery obj)
        {
            var res = await GetCInfoPwdByID(obj.CinfoId);
            var list = TableToList.ToList<MeetRoomPwd>(res);
            return list;

        }
        /// <summary>
        ///  获取会议室策略  
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<List<StrategyInfo>> GetStrategyInfo()
        {
            List<StrategyInfo> info = new List<StrategyInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetStrategyInfo";
            LogEntity.OperateObject = "GetStrategyInfo";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {

                var dt = await dal.GetStrategyInfo(out strError);
                if (strError == "")
                {
                    info = TableToList.ToList<StrategyInfo>(dt);


                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetStrategyInfo Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return info;
        }
        /// <summary>
        ///  获取会议室策略  
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<StrategyInfo> GetStrategyInfoByID(StrategyInfo query)
        {
            StrategyInfo info = new StrategyInfo();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetStrategyInfoByID";
            LogEntity.OperateObject = "GetStrategyInfoByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {

                var dt = await dal.GetStrategyInfoByID(query, out strError);
                if (strError == "")
                {
                    info = TableToList.ToList<StrategyInfo>(dt).FirstOrDefault();


                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetStrategyInfoByID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return info;
        }

        /// <summary>
        ///  查看所有会议信息会议室密码
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        /// <summary>
        ///  查看所有会议信息会议室密码
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageList<MeetingInfo>> GetAllCInfoPassWord(CInfoQuery query)
        {
            //TODO
            PageList<MeetingInfo> list = new PageList<MeetingInfo>();
            List<MeetingInfo> list1 = new List<MeetingInfo>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetAllCInfoPassWord";
            LogEntity.OperateObject = "GetAllCInfoPassWord";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var length = "";
                var setRes = setdal.GetSettingSystem(out strError).Result;
                var set = TableToList.ToList<SettingSystem>(setRes)[0];
                for (int i = 0; i < set.CNumberLength; i++)
                {
                    length += "0";
                }
                var res = await dal.GetAllCInfoByUser(query, out strError);
                list1 = TableToList.ToList<MeetingInfo>(res.Item1);
                var regional = setting.GetRegionalForMobile(new RegionalQuery()
                {
                    Key = "",
                    pageIndex = 1,
                    pageSize = 10000,
                });
                var regionalList = regional.Result.List;
                if (strError == "")
                {
                    list1.ForEach(i =>
                    {
                        i.MeetingNumber = set.CNumberPrefix + i.ID.ToString(length);
                        foreach (var item in regionalList)
                        {
                            if (i.RegionalID == item.ID)
                            {
                                i.RegionalName = item.RegionalName;
                            }
                        }
                        if (i.MeetState == 1)
                        {
                            i.State = "已预订";
                        }
                        else if (i.MeetState == 2)
                        {
                            i.State = "会议中";
                        }
                        else if (i.MeetState == 3)
                        {
                            i.State = "已结束";
                        }
                        else if (i.MeetState == 4)
                        {
                            i.State = "审批中";
                        }
                        else if (i.MeetState == 5)
                        {
                            i.State = "已取消";
                        }
                        else if (i.MeetState == 6)
                        {
                            i.State = "已作废";
                        }
                        else if (i.MeetState == 7)
                        {
                            i.State = "未通过";

                        }
                        else if (i.MeetState == 8)
                        {
                            i.State = "待发起";
                        }

                        i.date = Convert.ToDateTime(i.BeginTime).ToString("yyyy-MM-dd");
                        i.Start = Convert.ToDateTime(i.BeginTime).ToString("HH:mm");
                        i.End = Convert.ToDateTime(i.EndTime).ToString("HH:mm");
                    });
                    list.List = list1;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                    list.IsHaveNext = res.Item4;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetAllCInfoPassWord Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        public async Task<PageList<MeetRooMPIN>> GetCityCInfoPassWord(CInfoQuery query)
        {
            //TODO
            PageList<MeetRooMPIN> list = new PageList<MeetRooMPIN>();
            List<MeetRooMPIN> list1 = new List<MeetRooMPIN>();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetCityCInfoPassWord";
            LogEntity.OperateObject = "GetAllCInfoPassWord";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var length = "";
                var setRes = setdal.GetSettingSystem(out strError).Result;
                var set = TableToList.ToList<SettingSystem>(setRes)[0];
                for (int i = 0; i < set.CNumberLength; i++)
                {
                    length += "0";
                }
                var res = await dal.GetAllCInfoGroupByUser(query, out strError);
                list1 = TableToList.ToList<MeetRooMPIN>(res.Item1);
                foreach (var item in list1)
                {


                    CMSHttpHelper cMS = new CMSHttpHelper();

                    cMS.GetPassCode(item, out strError);
                }
                //var regional = setting.GetRegionalForMobile(new RegionalQuery()
                //{
                //    Key = "",
                //    pageIndex = 1,
                //    pageSize = 10000,
                //});
                //      var regionalList = regional.Result.List;
                if (strError == "")
                {
                    list1.ForEach(i =>
                    {


                        if (i.MeetState == 1)
                        {
                            i.State = "已预订";
                        }
                        else if (i.MeetState == 2)
                        {
                            i.State = "会议中";
                        }
                        i.date = Convert.ToDateTime(i.BeginTime).ToString("yyyy-MM-dd");
                        i.Start = Convert.ToDateTime(i.BeginTime).ToString("HH:mm");
                        i.End = Convert.ToDateTime(i.EndTime).ToString("HH:mm");
                    });
                    list.List = list1;
                    list.RecordCount = res.Item2;
                    list.PageCount = res.Item3;
                    list.IsHaveNext = res.Item4;
                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetAllCInfoPassWord Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return list;
        }
        /// <summary>
        /// 新增组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string, int)> OrgcalendarsOrder(MeetingOrder entity)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.OrgcalendarsOrder";
            LogEntity.OperateObject = "OrgcalendarsOrder";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {

                var result = await dal.CheckUserHaveCalendarsAuth(entity, out strError);
                if (!result)
                {
                    LogEntity.OperateResult = "Fail";
                    res = false;
                }
                else
                {
                    var (bResult, id) = await dal.OrgcalendarsOrder(entity, out strError);
                    if (!bResult)
                    {
                        LogEntity.OperateResult = "Fail";
                        res = false;
                    }

                    idd = id;
                }


            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("OrgcalendarsOrder Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }
        /// <summary>
        /// 编辑组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string, int)> UpdateOrgcalendars(MeetingOrder entity)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateOrgcalendars";
            LogEntity.OperateObject = "UpdateOrgcalendars";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {



                var result = await dal.CheckUserHaveCalendarsAuth(entity, out strError);
                if (!result)
                {
                    LogEntity.OperateResult = "Fail";
                    res = false;
                }
                else
                {
                    var (bResult, id) = await dal.UpdateOrgcalendars(entity, out strError);
                    if (!bResult)
                    {
                        LogEntity.OperateResult = "Fail";
                        res = false;
                    }
                    idd = id;
                }
            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("OrgcalendarsOrder Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }
        /// <summary>
        /// 取消组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<(bool, string, int)> DeleteOrgcalendars(MeetingOrder entity)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.DeleteOrgcalendars";
            LogEntity.OperateObject = "DeleteOrgcalendars";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<MeetingOrder>(entity);
            try
            {



                var result = await dal.CheckUserHaveCalendarsAuth(entity, out strError);
                if (!result)
                {
                    LogEntity.OperateResult = "Fail";
                    res = false;
                }
                else
                {
                    var (bResult, id) = await dal.DeleteOrgcalendars(entity, out strError);
                    if (!bResult)
                    {
                        LogEntity.OperateResult = "Fail";
                        res = false;
                    }
                    idd = id;
                }
            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("DeleteOrgcalendars Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }

        /// <summary>
        /// 根据会议ID获取日历信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MeetingInfoSingle> GetOrgcalendarsByID(CInfoQuery query)
        {
            MeetingInfoSingle meetingInfoSingle = new MeetingInfoSingle();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.GetOrgcalendarsByID";
            LogEntity.OperateObject = "GetOrgcalendarsByID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var res = await dal.GetOrgcalendarsByID(query, out strError);

                if (strError == "")
                {
                    meetingInfoSingle = TableToList.ToList<MeetingInfoSingle>(res.Item1).FirstOrDefault();
                    var roomlist = TableToList.ToList<MeetingRooms>(res.Item2);
                    var Participantlist = TableToList.ToList<Participant>(res.Item3);
                    meetingInfoSingle.date = Convert.ToDateTime(meetingInfoSingle.BeginTime).ToString("yyyy-MM-dd");
                    meetingInfoSingle.Begin = Convert.ToDateTime(meetingInfoSingle.BeginTime).ToString("HH:mm");
                    meetingInfoSingle.End = Convert.ToDateTime(meetingInfoSingle.EndTime).ToString("HH:mm");
                    if (string.IsNullOrEmpty(meetingInfoSingle.CostomCRoom))
                    {
                        meetingInfoSingle.CRooms = meetingInfoSingle.CRoom + "/" + meetingInfoSingle.CRooms;
                        meetingInfoSingle.CRooms = meetingInfoSingle.CRooms.Substring(0, meetingInfoSingle.CRooms.Length - 1);
                        meetingInfoSingle.CRoomIDs = meetingInfoSingle.CRoomID + "," + meetingInfoSingle.CRoomIDs;
                    }
                    else
                    {
                        meetingInfoSingle.CRooms = meetingInfoSingle.CostomCRoom;

                        meetingInfoSingle.CRoomIDs = "";
                    }

                    meetingInfoSingle.MeetingRoomsList = roomlist;
                    meetingInfoSingle.ParticipantList = Participantlist;


                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("GetOrgcalendarsByID Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return meetingInfoSingle;
        }

        /// <summary>
        /// 会议信息推送组织公共日历
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public (bool, string, int) InsertCInfoToOrgcalendars(int ID)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.InsertCInfoToOrgcalendars";
            LogEntity.OperateObject = "InsertCInfoToOrgcalendars";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {




                var (bResult, id) = dal.InsertCInfoToOrgcalendars(ID, out strError);
                if (!bResult)
                {
                    LogEntity.OperateResult = "Fail";
                    res = false;
                }
                idd = id;

            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("InsertCInfoToOrgcalendars Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }
        /// <summary>
        /// 根据会议ID更新组织日历并返回日历ID
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public (bool, string, int) InsertCInfoToOrgcalendarsForBPM(string strBOTID)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.InsertCInfoToOrgcalendarsForBPM";
            LogEntity.OperateObject = "InsertCInfoToOrgcalendarsForBPM";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {
                CInfoIds info = new CInfoIds();
                var resss = setdal.getMeetIdBystrBOID(strBOTID, out strError).Result;
                if (strError == "")
                {
                    info = TableToList.ToList<CInfoIds>(resss).FirstOrDefault();

                }
                else
                {
                    info = new CInfoIds();
                }
                if (info.IsPushEntWechat)
                {
                    var (obResult, OrgcalendarID) = dal.ChickOrgcalendarsIsHaveCInfo(info.CInfoID, out strError);
                    if (obResult && (OrgcalendarID > 0))
                    {
                        var (bResult, id) = dal.InsertCInfoToOrgcalendars(info.CInfoID, out strError);
                        if (!bResult)
                        {
                            LogEntity.OperateResult = "Fail";
                            res = false;
                        }
                        idd = id;
                    }


                }



            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("InsertCInfoToOrgcalendarsForBPM Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }

        public async Task<(bool, string, int)> UpdateOrgcalendarsByCInfoID(int ID)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.UpdateOrgcalendarsByCInfoID";
            LogEntity.OperateObject = "UpdateOrgcalendarsByCInfoID";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {
                var (obResult, OrgcalendarID) = dal.UpdateCInfoToOrgcalendars(ID, out strError);



            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("UpdateOrgcalendarsByCInfoID Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }
        public async Task<(bool, string, int)> deleteCInfoToOrgcalendars(int ID)
        {
            var res = true;
            int idd = 0;
            string strError = "";
            //string name = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.deleteCInfoToOrgcalendars";
            LogEntity.OperateObject = "deleteCInfoToOrgcalendars";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = "";
            try
            {
                var (obResult, OrgcalendarID) = dal.deleteCInfoToOrgcalendars(ID, out strError);

                idd = OrgcalendarID;

            }
            catch (Exception ex)
            {
                res = false;
                LogEntity.OperateResult = "Fail";
                strError = string.Format("deleteCInfoToOrgcalendars Exception:{0}", ex.ToString());

            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return (res, strError, idd);
        }

        /// <summary>
        /// 快速预定会议室
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MeetingInfoSingle> QuicklyMeetingOrder(CInfoQuery query)
        {
            MeetingInfoSingle meetingInfoSingle = new MeetingInfoSingle();
            string strError = "";
            LogEntity.Module = "XF.Meeting.Service.MeetingService.QuicklyMeetingOrder";
            LogEntity.OperateObject = "QuicklyMeetingOrder";
            LogEntity.OperateResult = "Success";
            LogEntity.OperationDescription = EntityToString.GetEntityToString<CInfoQuery>(query);
            try
            {
                var res = await dal.QuicklyMeetingOrder(query, out strError);

                if (strError == "")
                {

                    var list = TableToList.ToList<QuickMeet>(res.Item1);
                    if (list.Count > 0 && list != null)
                    {

                    }
                    else
                    {
                       var Roomlist = TableToList.ToList<QuickMeetRoom>(res.Item2);
                        var Infolist = TableToList.ToList<QuickMeetInfo>(res.Item3);
                        foreach (var room in Roomlist)
                        {
                            foreach (var Info in Infolist)
                            {
                                if(room.ID== Info.CroomID)
                                {
                                    room.infos.Add(Info);
                                }
                            }
                            for (int i = 0; i < room.infos.Count; i++)
                            {
                                
                            }

                        }
                       
                        
                    }

                }
                else
                {
                    LogEntity.OperateResult = "Fail";
                }
            }
            catch (Exception ex)
            {
                LogEntity.OperateResult = "Fail";
                strError = string.Format("QuicklyMeetingOrder Exception:{0}", ex.ToString());
            }
            LogEntity.ErrorDescription = strError;
            RecordLog();
            return meetingInfoSingle;
        }
    }

}
